/**
*   FuzzyEngine - an Simple flex framework 
*   Copyright (C) 2010 Constantin Aldea
*
*   This program is free software: you can redistribute it and/or modify
*   it under the terms of the GNU General Public License as published by
*   the Free Software Foundation, either version 3 of the License, or
*   (at your option) any later version.
*   This program is distributed in the hope that it will be useful,
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*   GNU General Public License for more details.
*
*   You should have received a copy of the GNU General Public License
*   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package main.com.sibilla.gadgets.views {
	import mx.containers.TitleWindow;
	import mx.containers.VBox;
	import mx.controls.Text;
	import mx.effects.Pause;
	import mx.effects.Resize;
	import mx.effects.Sequence;
	import mx.effects.easing.Circular;
	import mx.events.CloseEvent;
	import mx.events.EffectEvent;
	import mx.managers.PopUpManager;

	import flash.events.IEventDispatcher;

	public class WarningPopup extends TitleWindow implements IEventDispatcher
	{
		public static const POP_DURATION:int = 20000;
		private static const WARNING : String = "WARNING";

		/* private var _timer:Timer; */

		public function WarningPopup()
		{
			super();
			this.title = WARNING; 
			this.setStyle("textAlign", "left");
			this.setStyle("backgroundColor", "#E5E4E0");	
 			this.setStyle("borderStyle", "inset");
 			this.horizontalScrollPolicy = "off";
 			this.verticalScrollPolicy = "off";		
 			this.width = 330;
 			showCloseButton = true;
 			this.addEventListener(CloseEvent.CLOSE, closeInstance);
 	/* 		this._timer = new Timer();
 			this._timer.delay = WarningPopup.POP_DURATION;
 			this._timer.start(); */
		}
		

		   	 //----------------------------------
    		//  SETTER / GETTER FOR PUBLIC PROPS
   	 		//----------------------------------
   	 	
   	 	private var _message:String = '';
		private var _vBox:VBox;
		private var text:Text;
	
	
		public function set message(value:String):void{
   	 		_message = value;
   	 		this.invalidateProperties();
   	 	}
   	 	
   	 	override protected function commitProperties():void{
			super.commitProperties();
   	 	}
	
		override protected function createChildren():void{
			super.createChildren();
			text = new Text();
			text.text = _message; 	 		
	 		text.percentWidth = 100;
	 		text.percentHeight = 100;	
	 		text.width = this.width - 20;
			text.setStyle("fontSize", 11);
	 		_vBox = new VBox();
	 		_vBox.addChild(text);
			this.addChild(_vBox);
			this.x = stage.width - this.width  - 30;
			this.y = 20;
		}

		
		   	 //----------------------------------
    		//  OVERRIDEN METHODS
   	 		//----------------------------------
   	 	
   	 	override protected function measure():void{
   	 		super.measure();
   	 	}
   	 	
   	 	
		   	 //----------------------------------
    		//  PRIVATE METHODS
   	 		//----------------------------------   	 	
   	 	private function closeInstance(e:CloseEvent):void{
			var sequence:Sequence = new Sequence(this);
			var disp:WarningPopup =  e.currentTarget as WarningPopup;
			
			sequence.addEventListener(EffectEvent.EFFECT_END, function():void{
				PopUpManager.removePopUp(disp);
			});
			sequence.suspendBackgroundProcessing = true;
			var pause:Pause = new Pause();
			pause.duration = 400;
			sequence.addChild(pause);
			var resize:Resize = new Resize();
			resize.heightTo = 1;
			resize.duration = 300;
			resize.easingFunction = Circular.easeInOut;
			resize.suspendBackgroundProcessing = true;
			sequence.addChild(resize);
			var pause2:Pause = new Pause();
			pause2.duration = 300;
			pause2.suspendBackgroundProcessing = true;
			sequence.addChild(pause2);
			var resize2:Resize = new Resize();
			resize2.widthTo = 1;
			resize2.duration = 300;
			resize2.suspendBackgroundProcessing = true;
			resize2.easingFunction = Circular.easeOut;
			sequence.addChild(resize2);
			sequence.play();
   	 	}
	}
	

}